package cn.jia.spring5.Test;

import cn.jia.spring5.web.controller.HomeController;
import org.junit.Test;
import org.springframework.stereotype.Controller;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MockMvcBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup;

/**
 * Created by jia on 2018/4/4.
 */
public class HomeControllerTest {
    @Test
    public void testHomePage(){
        HomeController homeController = new HomeController();
        String home = homeController.getHome();
        System.out.println(home);

    }

    /**
     * 使用mock SpringMVC测试Controller
     */
    @Test
    public void testHomePage1() throws Exception {
        HomeController homeController = new HomeController();
        MockMvc mockMvc = standaloneSetup(homeController).build();
        mockMvc.perform(get("/homeInfo/getHome")).andExpect(view().name("spring5/home"));
        System.out.println();
    }
}
